Reject non-empty directories for new WSLC session storage#40655
Reject non-empty directories for new WSLC session storage#40655beena352 wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a wslcsession marker-file convention at the root of a WSLC session storage directory so the service can distinguish directories it owns from arbitrary user content, and rejects new session creation into a non-empty, unmarked directory. Also wires IErrorInfo/COMServiceExecutionContext through the per-user WSLCSessionFactory and WSLCSessionManager so the user-facing rejection message reaches the CLI/test caller.
Changes:
- Add
EnsureSessionMarkerhelper inWSLCSession::ConfigureStorage(new sessions require empty dir + stamp marker; existing VHD paths get a legacy upgrade stamp). - Add
ISupportErrorInfo+COMServiceExecutionContexttoWSLCSessionFactoryand propagateIErrorInfofrom factory to caller inWSLCSessionManagerImpl::CreateSession; addISupportErrorInfotoWSLCSessionManager. - Add API-level and e2e tests for marker rejection and legacy auto-upgrade; add localized
MessageWslcSessionStorageMustBeEmpty.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslcsession/WSLCSession.cpp | New EnsureSessionMarker helper and wiring into ConfigureStorage for new/existing storage paths. |
| src/windows/wslcsession/WSLCSessionFactory.cpp | Establish COMServiceExecutionContext around CreateSession and implement InterfaceSupportsErrorInfo. |
| src/windows/wslcsession/WSLCSessionFactory.h | Add ISupportErrorInfo base and method declaration. |
| src/windows/service/exe/WSLCSessionManager.cpp | Inspect IErrorInfo after factory failure and re-throw with user-facing message; implement InterfaceSupportsErrorInfo. |
| src/windows/service/exe/WSLCSessionManager.h | Add ISupportErrorInfo base and method declaration. |
| test/windows/WSLCTests.cpp | New API-level cases: non-empty dir rejection and wslcsession-as-directory rejection with COM error validation. |
| test/windows/wslc/e2e/WSLCE2ESessionEnterTests.cpp | E2E test verifying marker creation on default session and legacy auto-upgrade. |
| localization/strings/en-US/Resources.resw | New MessageWslcSessionStorageMustBeEmpty localized string. |
OneBlue
left a comment
There was a problem hiding this comment.
I think refusing to create a session storage if the directory is non-empty makes sense (although I worry a bit about this putting us in a corner, like if there's ever a thumdb.db, desktop.ini or similar file created, this could "lock a user out" of using that folder permanently)
I'm not sure about the marker file though. Whenever we create a storage folder, we always create a storage VHD, so could we use that directly instead ?
…slc-session-storage-marker
…eenachauhan/wslc-session-storage-marker
Summary of the Pull Request
Prevent users from accidentally reusing existing non-empty directories as WSLC session storage. For new sessions, validate that the storage directory is either empty or non-existent. Existing sessions identified by their storage.vhdx VHD bypass this check, so users can re-enter sessions freely even if additional files are present in the storage directory.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validate session storage paths at initialization time:
This prevents data loss by ensuring new sessions don't accidentally overwrite unrelated user files placed in the storage directory. Once a session is created (VHD exists), the directory can contain other files without blocking re-entry.
Validation Steps Performed